package com.yzk.aigy.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yzk.aigy.common.Result;
import com.yzk.aigy.model.system.SysLoginLog;
import com.yzk.aigy.model.vo.SysLoginLogQueryVo;
import com.yzk.aigy.service.SysLoginLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "登录日志控制器")
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/system/sysLoginLog")
public class SysLoginLogController {

    private final SysLoginLogService sysLoginLogService;

    @ApiOperation("获取分页列表（登录日志）")
    @PostMapping("page")
    public Result<IPage<SysLoginLog>> QueryLoginLog(@RequestBody SysLoginLogQueryVo sysLoginLogQueryVo) {
        return Result.ok(sysLoginLogService.selectPage(sysLoginLogQueryVo));
    }

    @ApiOperation("根据ID获取登录日志")
    @GetMapping("/get/{id}")
    public Result<SysLoginLog> get(@PathVariable Long id) {
        return Result.ok(sysLoginLogService.getById(id));
    }

    @ApiOperation("获取全部日志")
    @GetMapping("/findAll")
    public Result<List<SysLoginLog>> findAll() {
        return Result.ok(sysLoginLogService.list());
    }

    @ApiOperation("根据ID移除日志")
    @DeleteMapping("/removeLoginLog/{id}")
    public Result<Object> removeCategory(@PathVariable Long id) {
        return sysLoginLogService.removeById(id) ? Result.ok() : Result.fail();
    }

    @ApiOperation("批量删除日志")
    @DeleteMapping("/removeLoginLogByIds")
    public Result<Object> removeCategoryByIds(@RequestBody List<Long> ids) {
        return sysLoginLogService.removeByIds(ids) ? Result.ok() : Result.fail();
    }

}
